package com.woniuxy.controller;

import com.woniuxy.entity.*;
import com.woniuxy.service.PaperClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags="查询试卷类别")
@RestController
@RequestMapping("/paper_category")
public class PaperClassController {
    @Autowired
    PaperClassService paperClassService;

    @ApiOperation("查询试卷菜单")
    @GetMapping("/findAll")
    public ResponseEntity findAll(){

        return paperClassService.findAll();
    }
//    @ApiOperation("条件查询考试列表")
//    @GetMapping("find/{currentPage}/{pageSize}")
//    public ResponseEntity find(@PathVariable int currentPage,@PathVariable int pageSize){
//        return paperClassService.find(currentPage,pageSize);
//    }

    @ApiOperation("查询总条数")
    @GetMapping("/findAll/findTotalNumber")
    public ResponseEntity findTotalNumber(){
        return  paperClassService.findTotalNumber();
    }
    @ApiOperation("查询当前页，每页条数")
    @GetMapping("/findAll/{currentPage}/{pageSize}")
    public ResponseEntity findAll(@PathVariable int currentPage, @PathVariable int pageSize){
        System.out.println(currentPage);
        return  paperClassService.findAll(currentPage, pageSize);
    }

    //根据id，删除试卷菜单中的指定类别

    @ApiOperation("删除试卷菜单中的类别")
    @GetMapping("/delete/{id}")
    public ResponseEntity deleteclass(@PathVariable("id") int id){
        return paperClassService.deleteById(id);
    }

//    @ApiOperation("批量删除试卷菜单中的类别")
//    @PostMapping("/batchdelete")
//    public void batchDelete(@RequestBody int[] id){
//        for(int i = 1; i <= id.length; i++) {
//            System.out.println("sdbgjk");
////            paperClassService.deleteById(i);
//        }
//
//    }
//    新增试卷分类

    @ApiOperation("新增试卷分类")
    @PostMapping("/insertclass")
    public ResponseEntity insertClass(@RequestBody PaperClassEntity paperClassEntity){
        return paperClassService.insertClass(paperClassEntity);
    }

    /**在新增试卷分类前需要把原本fid为0的category访问出来*/
    @ApiOperation("新增试卷分类之前")
    @GetMapping("/findFid")
    public ResponseEntity findFid(){
//        System.out.println("修改试卷分类");
//        System.out.println(paperClassEntity.getId());
//        System.out.println(paperClassEntity.getCategory());
        return paperClassService.findFid();
    }
    /**在修改前需要把原本的内容查询出来，渲染到页面上*/
    @ApiOperation("修改试卷分类之前")
    @PostMapping("/updateBefore")
    public ResponseEntity updateBefore(@RequestBody PaperClassEntity paperClassEntity){
//        System.out.println("修改试卷分类");
//        System.out.println(paperClassEntity.getId());
//        System.out.println(paperClassEntity.getCategory());
        return paperClassService.updateBefore(paperClassEntity);
    }

    /**根据数据库id修改试卷分类*/
    @ApiOperation("修改试卷分类")
    @PostMapping("/updateclass")
    public ResponseEntity updateClass(@RequestBody PaperClassEntity paperClassEntity){
//        System.out.println("修改试卷分类");
//        System.out.println(paperClassEntity.getId());
//        System.out.println(paperClassEntity.getCategory());
        return paperClassService.updateClass(paperClassEntity);
    }

    /*批量删除*/

    @ApiOperation("批量删除")
    @PostMapping("/batchdelete")
    public ResponseEntity batchDelete(@RequestBody PaperClassEntity paperClassEntity){
        System.out.println(paperClassEntity);
        return paperClassService.batchDelete(paperClassEntity);
    }
//    按试卷分类名称搜索

    @ApiOperation("按试卷分类名称搜索")
    @PostMapping("/searchclass")
    public ResponseEntity searchClass(@RequestBody PaperClassEntity paperClassEntity){
//        System.out.println(currentPage);
//        System.out.println("sadf:"+pageSize);
        System.out.println(paperClassEntity);
        return paperClassService.searchClass(paperClassEntity);
    }
   /* @GetMapping("/insertclass")
    public void insertclass(@PathVariable("list") List list){
        paperClassService.updateById(list);
    }*/



}
